home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple II Magazines (PO)
/
Nibble Volume 12, No. 01 (1991-01)(MindCraft Publishing)(Side A)[a].zip
/
Nibble Volume 12, No. 01 (1991-01)(MindCraft Publishing)(Side A)[a].po
/
MOUSE.CLOCK.SRC.txt
< prev
next >
Wrap
Text File
|
1996-12-24
|
8KB
|
402 lines
**********************************
* MOUSE.CLOCK Source Code *
* By John R. Vokey *
* (C) 1991 by MindCraft Publ. *
**********************************
;
;
*=================================
; Equates
*=================================
;
* Set System DOS:
PRODOS EQU $21 PRODOS = $21, DOS = 0
;
* Monitor:
ACC EQU $45 save A loc on IRQ
SAVEA EQU $FC temp for Acc
SAVEX EQU SAVEA+1 temp for X reg
SAVEY EQU SAVEX+1 temp for Y reg
SCREEN EQU $41D 40-col screen position
USER EQU $0000 User's interrupt handler
;
* Applesoft:
CHKCOM EQU $DEBE Check for comma at TXTPTR
PTRGET EQU $DFE3 returns variable pointer
VARPNT EQU $83 Applesoft pointer
ERROR EQU $D412 error routine
;
* Mouse:
MSLOT EQU $C400 assume slot 4
NUM EQU $FF used as a temp
;
* ProDOS:
ALLOC EQU $40 allocate interrupt code
MLI EQU $BF00 Machine Language Interface
DATETIME EQU $BF06 Date/time jump
PTIME EQU $BF92 time locations
BITMAP EQU $BF58 system bit map
GOSYSTEM EQU $BE70 BASIC.SYSTEM command call
GETBUFR EQU $BEF5 Get Buffer
ERROUT EQU $BE09 error exit
;
* DOS 3.3:
BUFCNT EQU $AA57 # of buffers to create
BUFPTR EQU $9D00 pointer to new buffer
BUFBLD EQU $A7D4 build buffers
DOSLOC EQU $9C00 relocation page
;
* Origin:
ORG $4000-$44-PRODOS
;
*=================================
; Relocate
*=================================
;
DO PRODOS
LDA #1 ask BASIC.SYSTEM for 1 page
JSR GETBUFR
BCS BADERR Error
STA VARPNT+1 (for move)
PHA save it
LSR A shift down
LSR A
LSR A
TAX use as index into bitmap
PLA
EOR #$FF complement
AND #$7 mask off high bits
SEC
TAY
LDA #0 clear Acc
PLOOP ROL A shift 'Y' times
DEY
BPL PLOOP
ORA BITMAP,X set bit
STA BITMAP,X flag "used"
LDA VARPNT+1 recover hbyte
STA P2
STA P4+1
;
ELSE
LDA #>DOSLOC lbyte of space
SEC
SBC #$26 name, pointers, etc.
STA BUFPTR
LDA #<DOSLOC hbyte
SBC #0
STA BUFPTR+1
LDA #3 set default (3) buffers
STA BUFCNT
JSR BUFBLD create space
LDA #<DOSLOC
STA D2+1
FIN
;
MOVE LDY #0
STY VARPNT
STA VARPNT+1
MLOOP LDA SETMOUSE,Y
STA (VARPNT),Y
DEY
BNE MLOOP
;
LDX RBYTES get # of bytes
LDA VARPNT+1 recover page #
RLOOP PHA
LDA RBYTES,X get index of byte to fix
TAY use Y as index
PLA
STA (VARPNT),Y fix it
DEX more?
BNE RLOOP Yes, loop until done
;
*=================================
; Initialize
*=================================
;
DO PRODOS
JSR MLI call command dispatcher
DFB ALLOC to install interrupt
DW PRMLST handler
BCC DOTIME
BADERR JMP ERROUT exit if error
PRMLST DFB 2,0
DFB >IHAND
P2 DFB <IHAND
;
ELSE
* set DOS interrupts
LDA #>IHAND
STA $3FE
D2 LDA #<IHAND
STA $3FF
FIN
;
* Setup ProDOS time call:
DOTIME DO PRODOS
LDA #$4C a "JMP"
STA DATETIME
LDA #>SAVTIME and point to
STA DATETIME+1 time routine
P4 LDA #<SAVTIME
STA DATETIME+2
FIN
;
*=================================
; Start Clock
*=================================
;
; The mouse will be placed in
; TRANSPARENT mode with the vertical
; blanking signal active such that
; each VBL will result in an interrupt.
; Since VBL occurs once every 1/60 of
; a second, 3 VBLs is equivalent to
; 5 centiseconds.
;
* Permanent code begins here
;
SETMOUSE LDY #$19
M1 JSR CALL do INITMOUSE
BCS MSEERR if error, exit
SEI Disable Interrupts
;
SETMODE LDA #$9 set TRANSPARENT mode
SETMDE LDY #$12 (VBLINT active)
M2 JSR CALL do SETMOUSE
BCS MSEERR if error, exit
CLI enable interrupts
RTS Done
;
MSEERR LDX #$17 make "ERROR"
JMP ERROR
;
*=================================
; Kill Mouse
*=================================
;
; Call this routine to turn mouse.clock
; off; call the above routine to start
; it again.
;
KILLMSE SEI turn off interrupts
LDA #0 mouse off
BEQ SETMDE do SETMOUSE, exit
;
*=================================
; Call Mouse
*=================================
;
; Input: A - mode (if any)
; Y - offset to command call
; - assumes mouse in MSLOT
; Output: X, Y, A scrambled
;
CALL PHA save mode
LDA MSLOT,Y get low byte
R1 STA DOIT+1 self-modifying code
LDX #<MSLOT X, Y housekeeping
LDY #<MSLOT-$C000*$10
PLA recover mode
DOIT JMP MSLOT do mouse call, exit
;
*=================================
; Interrupt Handler
*=================================
;
IHAND CLD ProDOS wants this
LDA $45 save regs for old monitors
STA SAVEA
STX SAVEX
STY SAVEY
LDY #$13 Who interrupted?
R2 JSR CALL do SERVEMOUSE
BCS EXIT Not mouse, so go
SEI Mouse, so disable interrupts
;
*=================================
; Function: TIME$
*=================================
;
; This routine adds a TIME$ function
; to Applesoft BASIC. On every
; 3 vertical blanks, the time count for
; CSECS, SECS, MINS, and HOUR is updated.
; The time is then converted to its
; ASCII equivalent in a HH:MM:SS CS
; format and stored in OUTSTR.
; If screen display is selected
; (DSPTGL = TRUE), OUTSTR is output
; to the screen at SCREEN.
;
TIMER DEC TIMECNT count 3 cycles
BNE EXIT If not 0, go
LDY #3 reset cycle count
T1 STY TIMECNT
LDA #5 increment msecs
TLOOP ADC TIME,Y increment counter
CMP TIMLIM,Y counter done?
STA TIME,Y
LDA #0
BCC NXTCNT no, next counter
T2 STA TIME,Y yes, clear it
NXTCNT DEY next counter, please
BPL TLOOP and go again
;
F1 LDA TIME get hours
BNE TIMEOUT if not 0, go
F2 LDA TIMLIM get clock type
CMP #24 24-hour clock?
BEQ TIMEOUT yes, go
F3 INC TIME make hours = 1
;
TIMEOUT LDX #0 Init OUTSTR ptr
LDY #0 start with hours
TOUTLP TYA save Y
PHA on stack
T3 LDA TIME,Y get time count
STA NUM save number
LDY #1 init to 10^1
INLOOP LDA #0 assume zero
PHA save it
LOOP LDA NUM recover number
T4 CMP POFTEN,Y >= 10^Y?
BCC NUMOUT No, done
T5 SBC POFTEN,Y Yes, divide by subtraction
STA NUM save remainder
PLA count divisions
SEC add 1 to Acc
ADC #0
PHA save again
BCC LOOP always taken
NUMOUT PLA recover digit (0-9)
ORA #$30 ASCII "0" + digit
T6 STA OUTSTR,X save ASCII equivalent
INX next output loc
DEY next digit
BPL INLOOP
INX skip delimiter
PLA recover Y
TAY
INY
CPY #4 All done?
BCC TOUTLP No, go again
S1 LDA DSPTGL Yes, display to screen?
BEQ ALLDONE No, go
LDY #10 else, 11 chars to go
S2 LDA OUTSTR,Y get char
STA SCREEN,Y store to screen
DEY
BPL S2
ALLDONE CLC mark successful call
;
*=================================
; Exit
*=================================
;
EXIT DO USER
JSR USER do User's handler
ELSE
NOP
NOP
NOP
FIN
;
LDA SAVEA recover regs
STA $45 how we were called...
LDX SAVEX
LDY SAVEY
;
DO PRODOS
NOP keeps offsets equal
RTS
;
ELSE
CLI for DOS
RTI
FIN
;
*=================================
; Internal variables
*=================================
;
TIMECNT DFB 3
DSPTGL DFB 0 init to off
TIME DFB 0,0,0,0
TIMLIM DFB 24,60,60,100
POFTEN DFB 1,10
MSB OFF
OUTSTR ASC '00:00:00 00'
PTR DFB 11,>OUTSTR,<OUTSTR
;
*=================================
;Assign OUTSTR to user's variable:
*=================================
;
; Points the user's string variable
; at OUTSTR. From BASIC:
; LET ASSIGN = Address
; CALL ASSIGN,TIME$
; Then PRINT TIME$ will return
; the current time. The value of TIME$
; will automatically be updated.
;
ASSIGN JSR CHKCOM check for comma
JSR PTRGET locate variable
LDY #2 offset to pointer
ALOOP LDA PTR,Y
STA (VARPNT),Y
DEY
BPL ALOOP
RTS
;
*=================================
; Display Switch
*=================================
;
; Calling this routine toggles
; screen display on/off.
;
DISPSWCH LDA DSPTGL get value
EOR #$FF toggle
S3 STA DSPTGL
RTS exit
;
*=================================
; ProDOS TIME call
*=================================
;
; Updates the ProDOS time locations
; when called by the MLI.
;
SAVTIME DO PRODOS
P5 LDA TIME+1
STA PTIME
P6 LDA TIME
STA PTIME+1
RTS
FIN
;
*=================================
; Relocation Bytes
*=================================
;
RBYTES DO PRODOS
DFB 25
;
ELSE
DFB 23
FIN
;
DFB M1+2,M2+2
DFB R1+2,R2+2,TIMER+2,T1+2
DFB TLOOP+2,TLOOP+5,TLOOP+8
DFB T2+2,F1+2,F2+2,F3+2,T3+2,T4+2,T5+2,T6+2
DFB S1+2,S2+2,PTR+2
DFB ALOOP+2,DISPSWCH+2,S3+2
;
DO PRODOS
DFB P5+2,P6+2
FIN